package com.gupao.edu.study.prototype;

import java.io.*;
import java.util.Date;

/**
 * @Author: guqy
 * @Description:
 * @Date 14:14 2018/3/19
 */
public class UserClone implements Cloneable,Serializable{

    //编号
    private Integer userId;

    //帐号
    private String username;

    //密码MD5(密码+盐)
    private String password;

    //盐
    private String salt;

    //创建日期
    private Date date;

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public UserClone deepCloneMethod() {
        ByteArrayOutputStream bos = null;
        ByteArrayInputStream bis = null;
        try {
            bos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(bos);
            out.writeObject(this);
            byte[] bytes = bos.toByteArray();
            out.flush();
            out.close();

            bis = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bis);
            UserClone cloneObject = (UserClone) ois.readObject();
            ois.close();
            return cloneObject;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            try {
                bos.close();
                bis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
